function diff = J_p_fun( m, param)
    % calculates J\prime(m) 
    if param.K>0
        diff = J_n_p(m,param).*(m>=param.m_l).*(m<param.m_h) ...
            +(m>=param.m_h).*(m<param.m_e).*J_r_p(m,param) ...
            +(m>=param.m_e).*0;
    else
        diff = J_n_p(m,param).*(m>=param.m_l).*(m<param.m_h) ...
            +(m>=param.m_h).*0;    

    end
end